/**==================================
 * 封装请求并绑定模板
 * @author 冯胜德
 * ==================================
 */
;(function() {
	$.fn.httpFetch = function(url, params, tpl,callback) {
		var thisContainer = this;
		var index = layer.load();
		layui.use([ 'laytpl', 'layer' ], function() {
			var laytpl = layui.laytpl, layer = layui.layer;
				$.myPost(url, params, function(result, status) {
					layer.close(index);
					if(callback != null){
						callback();	
					}
					if (result.code == 200) {
						console.log(result);
						$(thisContainer).empty();
						laytpl(tpl).render(result, function(html) {
							console.log(html);
							$(thisContainer).append(html);
						});
					} else {
						console.log(result);
						layer.msg(result.info);
					}
				});	
		});
	};
	
	$.myPost = function(url,model,callback){
		var index = layer.load();
		$.post(url, model, function(result, status) {
			layer.close(index);
			callback(result, status);
		}).error(function() { 
			layer.msg("网络错误");
		})
	}
})();